import { setGlobal } from '@swda/utils'

function Sprite_PasswordButton() {
    this.initialize.apply(this, arguments);
}

Sprite_PasswordButton.prototype = Object.create(Sprite_Button.prototype);
Sprite_PasswordButton.prototype.constructor = Sprite_PasswordButton;

Sprite_PasswordButton.prototype.initialize = function() {
    Sprite_Button.prototype.initialize.call(this);
    this._buttonOnSprite = new Sprite();
    const buttonWidth = 175;
    const buttonHeight = 87;
    this._buttonOnSprite.bitmap = ImageManager.loadBitmap('img/system/UI/', 'ButtonOnPassword');
    this._buttonOnSprite.setFrame(0, 0, buttonWidth, buttonHeight);
    this.addChild(this._buttonOnSprite);
    this._onFrameCount = 0;
    this._isSelected = false;
    this._buttonOnSprite.visible = false;
};

Sprite_PasswordButton.prototype.update = function () {
    Sprite_Button.prototype.update.call(this);
    this.updateOnFrame();
};

Sprite_PasswordButton.prototype.selected = function () {
    this._isSelected = true;
    this._buttonOnSprite.visible = true;
};
Sprite_PasswordButton.prototype.deselected = function () {
    this._isSelected = false;
    this._buttonOnSprite.visible = false;
};
Sprite_PasswordButton.prototype.updateOnFrame = function () {
    if(this._isSelected){ 
    if ((this._onFrameCount/10) == Math.floor(this._onFrameCount/10)){
        const i = Math.floor(this._onFrameCount/10) % 6;
        const buttonWidth = 175;
        const buttonHeight = 87;
        this._buttonOnSprite.setFrame(0, i * buttonHeight, buttonWidth, buttonHeight);
    }
    this._onFrameCount += 1;
    this._onFrameCount = this._onFrameCount % 60;
    }

};

setGlobal('Sprite_PasswordButton', Sprite_PasswordButton)